<template>
<!--pages/personalCenter/personalCenter.wxml-->
<view class="personal-center">
  <!-- 头部 -->
  <view class="personal-header">
    <image v-if="loginStatus" src="/static/images/person/pic_userbg.png" class="user-bg"></image>
    <image v-else src="/static/images/person/pic_userbg_no.png" class="user-bg"></image>
    <!-- 头部主体 -->
    <view class="user-header-main" v-if="loginStatus">
      <!-- 昵称 -->
      <view class="user-name-box">
        <text>{{userInfo.userName}}</text>
        <image src="/static/images/icon/icon_modify.png" class="icon-modify"></image>
      </view>
      <!-- 头像及会员等级 -->
      <view class="user-avatar-box">
		  <view class="user-avatar">
			  <image :src="userInfo.icon" class="user-avatar"></image>
		  </view>
        
        <image src="/static/images/icon/icon_level.png" class="icon-level"></image>
        <text class="text-level">普通会员</text>
      </view>
      <!-- 会员福利 -->
      <view class="benefit">
        <view class="benefit-item">
          <text class="benefit-point"></text>
          <text>含早餐</text>
        </view>
        <view class="benefit-item">
          <text class="benefit-point"></text>
          <text>1倍积分</text>
        </view>
        <view class="benefit-item">
          <text class="benefit-point"></text>
          <text>9.9折房费</text>
        </view>
        <view class="benefit-item">
          <text class="benefit-point"></text>
          <text>13:00退房</text>
        </view>
      </view>
      <!-- 会员等级提示 -->
      <view class="level-info">
        当前消费<text class="level-money">￥288</text>，再消费￥712将升级至中级会员
      </view>
    </view>
		
		
		<view class="user-header-main-login" v-else>
		  <view class="login" @click.stop="navTo('/pages/public/login_choose')">登录 | 注册</view>
		</view>

	</view>
  <!-- 我的订单+待入住 -->
  <view class="order-check">
    <view class="order-check-item" hover-class="user-hover-class" @click="navTo('/pages/order/mode?state=0')">
        <image class="order-check-img" src="/static/images/icon/icon_order.png" mode="aspectFit"></image>
        <view>我的订单</view>
    </view>
    <view class="order-check-item" hover-class="user-hover-class" @click="navTo('/pages/order/mode?state=2')">
        <image class="order-check-img" src="/static/images/icon/icon_check.png" mode="aspectFit"></image>
        <view>待入住</view>
    </view>
  </view>
  <!-- 待付款+我的积分+优惠券+我的社交账号 -->
  <view class="func-box">
    <view v-for="(item, index) in personalFuncList" :key="index" class="func-item" :data-url="item.toUrl" hover-class="user-hover-class" @tap="butnav">
      <image class="func-icon" :src="item.icon" mode="aspectFit"></image>
      <text class="func-text">{{item.text}}</text>
      <image class="func-right_icon" src="/static/images/icon/icon_right.png"></image>
    </view>
  </view>
  <view class="func-box">
    <view class="func-item" hover-class="user-hover-class" @click="navTo(99)" v-if="loginStatus">
      <image class="func-icon" src="/static/images/icon/icon_contact.png" mode="aspectFit"></image>
      <text class="func-text">退出登录</text>
      <image class="func-right_icon" src="/static/images/icon/icon_right.png"></image>
    </view>
  </view>
  <view class="func-box">
    <view class="func-item" hover-class="user-hover-class" @click="navTo('/pages/personalCenter/about')" v-if="loginStatus">
      <image class="func-icon" src="/static/images/icon/icon_about.png" mode="aspectFit"></image>
      <text class="func-text">关于肯天</text>
      <image class="func-right_icon" src="/static/images/icon/icon_right.png"></image>
    </view>
  </view>
</view>
</template>

<script>
// import store from "@/utils/store.js";
    import {_userInfo, _judgeBingingPhone} from '../../common/vmeitime-http/user.js'
	import {_verified} from '../../common/vmeitime-http/mem.js'
	import {_logout} from '../../common/vmeitime-http/login.js'
// import store from "../utils/store.js"
export default {
	data(){
				return {
					personalFuncList: [{
						icon: "/static/mine/daifukuan@2x.png",
						text: '待付款',
						toUrl:"/pages/order/mode?state=1"
					}, {
						icon: "/static/images/icon/icon_coin.png",
						text: '我的积分',
						toUrl: '/pages/integral/index'
					},{
						icon: "/static/images/icon/icon_coupon.png",
						text: '入住人管理',
						toUrl: '/pages/address/address'
					}],
					coverTransform: 'translateY(0px)',
					coverTransition: '0s',
					moving: false,
					loginStatus:false,//登陆状态
					userInfo:{},
					userNum:[0,0,0,0],
					signStatus:false//认证状态
				}
			},
  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    // this.userInfo = store.getItem("userInfo");
    // console.log(this.userInfo);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  async onShow(){
		console.log('进页面了')
              this.loginStatus = uni.getStorageSync('authInfo')?true:false;
							console.log(this.loginStatus)
  //            let _userInfoTemp = uni.getStorageSync('wxUserInfo');
  //            if(_userInfoTemp){
  //                this.userInfo = _userInfoTemp
  //            }
              if(this.loginStatus){
				  this.userInfo = uni.getStorageSync('userInfo')
  				// this.judgeBingingPhone();
				
	// --------------------------获取用户信息-----------
    //             let tempData = await _userInfo();
    //             uni.setStorageSync('relUserInfo',tempData.data.data);
  				// this.userNum[0]=tempData.data.data.waitPayNum;
  				// this.userNum[1]=tempData.data.data.waitReceiveNum;
  				// this.userNum[2]=tempData.data.data.waitEvaluateNum;
  				// this.userNum[3]=tempData.data.data.afterSaleNum;
				// if(tempData.data.code==200){
                  if(0){
                      setTimeout(()=>{
                          let _userInfoTemp = uni.getStorageSync('wxUserInfo');
                          if(_userInfoTemp){
                              this.userInfo = _userInfoTemp
                          }
  					},600)
  				}else{
                      this.userNum=[0,0,0,0];
  				}
  				// this.gotSign();
  			}else{
                  this.userNum=[0,0,0,0];
  			}
  		},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
		/**
		 * 统一跳转接口,拦截未登录路由
		 * navigator标签现在默认没有转场动画，所以用view
		 */
		navTo(url){
			if(url == 99 && uni.getStorageSync('userInfo')){
				uni.showModal({
				    title: '提示',
				    content: '是否退出',
				    success: function (res) {
				        if (res.confirm) {
				            uni.showLoading({
				            	title:"退出中"
				            })
				            uni.removeStorageSync('authInfo')
				            uni.removeStorageSync('wxUserInfo')
				            uni.removeStorageSync('userInfo')
				            uni.removeStorageSync('equipmentlist')
				            uni.removeStorageSync('controller')
				            uni.removeStorageSync('supertest')
				            uni.showToast({
				            	title:"退出成功",
				            	success() {
				            		uni.switchTab({
				            			url:'/pages/index/index'
				            		})
				            	}
				            })
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
				
				
			}
			if(!this.loginStatus){
			    if(url!=="/pages/explain/about"){
		                  url = '/pages/public/login_choose';
				}
			}
			uni.navigateTo({
				url
			})
		}, 
		
		async gotSign(){
		    let tempData = await _verified({})
			if(tempData.data.code==200){
			    this.signStatus = tempData.data.data==1?true:false
			}
		},
		
		butnav(e){
			console.log(e)
			var url = e.currentTarget.dataset.url;
			this.navTo(url);
		},
	}
};
</script>
<style>
@import "./personalCenter.css";
</style>